#!/bin/sh

FILE=`zenity --file-selection --title="Select a File"`

case $? in
         0)
                echo "\"$FILE\" selected."
		
		mkdir -p out
		pdfseparate $FILE out/out-%d.pdf
		for fp in $(ls out/out-*.pdf)
		do
			rf=`pdftotext $fp - | grep -A 2 ASSU | tail -n 1`
			mv "$fp" "out/$rf.pdf"
	
		done
		
		zp=buste_`date +%Y%m%d_%H%M%S`.zip 
		zip "$zp" -mr out
		zenity --info --text="Nome archivio creato $zp "
		;;
         1)
                echo "No file selected.";;
        -1)
                echo "An unexpected error has occurred.";;
esac


